[#include "/WEB-INF/pages/common/taglibs.ftl"]
[#if piece == true]
	[@demo.tableDisplayer id="fileListTable" renderTo="resourceList" ajaxPage="true" property="fileList" pagesize=4 page="/manage/Resource_list.action" name="FreemarkerTable" config="/WEB-INF/component/table/template-stdtable-autopage.ftl" bundle="messageSource"]
		[@demo.column name="-" property="path" innerHtml="\linput style='width:35px;' class='center span-atom' type='checkbox'/\g" headHtml="\linput type='checkbox' class='checkall' /\g" footHtml="&nbsp;" title="ID" columnClass="center span-atom"/]
		[@demo.column name="name" property="name" title="名称" columnClass=""/]
		[@demo.column name="size" property="size" title="大小" columnClass="span1"/]
		[@demo.column name="modifyDate" property="modifyDate" title="修改时间" columnClass="span1-1"/]
		[@demo.column name="operate" property="path" title="操作" columnClass="span2-1" innerHtml="\la href='javascript:void(0);' class='anchorbutton button_editor confirmbutton' act='edit' \g\lspan\g编辑\l/span\g\l/a\g&nbsp;|&nbsp;\la href='javascript:void(0);' class='anchorbutton button_trash confirmbutton' act='delete' \g\lspan\g删除\l/span\g\l/a\g" headerClass="batch"/]
	[/@demo.tableDisplayer]
[#else]
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Insert title here</title>
		<meta name="menu" content="AdminMenu"/>
		<meta name="heading" content="resource"/>
		<!-- The localization script
		<script src="[@c.url value='/js/plugins/jquery-fileupload/js/locale.js'/]"></script> -->
		<link rel="stylesheet" href="[@c.url value='/js/plugins/jquery-ztree/css/zTreeStyle/zTreeStyle.css'/]" type="text/css">
		<link rel="stylesheet" href="[@c.url value='/style/plugins/codemirror/codemirror.css'/]">
		<script type="text/javascript" src="[@c.url value='/js/custom/media.js'/]"></script>
		<script type="text/javascript" src="[@c.url value='/js/custom/tables.js'/]"></script>
		<script type="text/javascript" src="[@c.url value='/js/plugins/jquery.alerts.js'/]"></script>
		<script type="text/javascript" src="[@c.url value='/js/plugins/jquery-ztree/js/jquery.ztree.core-3.1.js'/]"></script>
		<script src="[@c.url value='/js/plugins/codemirror/codemirror.js'/]"></script>
		[#--
		<script type="text/javascript" src="[@c.url value='/js/plugins/wysiwyg/jquery.wysiwyg.js'/]"></script>
		<script type="text/javascript" src="[@c.url value='/js/plugins/wysiwyg/wysiwyg.image.js'/]"></script>
		<script type="text/javascript" src="[@c.url value='/js/plugins/wysiwyg/wysiwyg.link.js'/]"></script>
		<script type="text/javascript" src="[@c.url value='/js/plugins/wysiwyg/wysiwyg.table.js'/]"></script>
		--]
		<style type="text/css">
			.resource {
				width:500px;
			}
			.note { 
				height: 51px; overflow: hidden; position: relative; /*margin-bottom: 20px;*/ margin-bottom: 6px; -moz-border-radius: 2px; -webkit-border-radius: 2px; border-radius: 2px; 
				-moz-box-shadow: 1px 1px 2px #ddd;
			}
			.note p { margin: 14px 10px 0 75px; font-size: 13px; color: #333; }
			.note a.close { 
				position: absolute; width: 14px; height: 14px; top: 5px; right: 5px; background-image: url(../images/close.png); background-repeat: no-repeat; }
			.note a.close:hover { cursor: pointer; }
			/** 选中行高亮 **/
			.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}
      		.activeline {background: #e8f2ff !important;}
      		/** 全屏 **/
      		.CodeMirror-fullscreen {
		        display: block;
		        position: absolute;
		        top: 0; left: 0;
		        width: 100%;
		        height:100%;
		        z-index: 9999;
		     }
		</style>
		 
		<script type="text/javascript">
			var base = (function(){
				// 事件绑定
				function _addEventListeners() {
					// 维护
					$('a[act=edit]').unbind('click').click(function(){
						var path = $(this).parent().attr('tval');
						[@c.url var="url" value='/manage/Resource_view.action' scope="page"]
						[/@c.url]
						$.get("${url}", {path:path, ajax:true, piece:true}, function(data) {
							$('#resourceList').html(data);
						})
					})
					
					// 删除
					$('a[act=delete]').unbind('click').click(function(){
						var path = $(this).parent().attr('tval');
						var title = $('#delete-confirm').attr('title');
						var content = $('#delete-confirm').html();
						jConfirm(content, title, function(r) {
							if (r) {
								[@c.url var="backUrl" value="/manage/Resource_list.action"]
								[/@c.url]
								[@c.url	var="deleteUrl" value='/manage/Resource_delete.action' scope="page"]
									[@c.param name="backUrl" value="${backUrl}"/]
									[@c.param name="path" value=""/]
								[/@c.url]
								//$.get("${deleteUrl}", {path:path, ajax:true, piece:true}, function(data) {
								//	$('#resourceList').html(data);
								//})
								window.location	= "${deleteUrl}" + path;
							}
						});
						return false;
					})
				}
				function _addDateTableRender() {
					$('#dyntable').unbind().bind('sort', function (){_addEventListeners();})
						.dataTable( {
							"sPaginationType": "full_numbers",
						 	"oLanguage": {
							 	"sSearch": "检索：",
					            "sLengthMenu": "每页显示 _MENU_ 条记录",
					            "sZeroRecords": "未找到数据.",
					            "sInfo": "显示 _START_-_END_ 条  【共 _TOTAL_ 条】",
					            "sInfoEmpty": "显示 0-0 条 共 0 条",
					            "sInfoFiltered": "(filtered from _MAX_ total records)",
					            "oPaginate": {
					            	"sFirst": "首页",	            	
					            	"sPrevious": "上一页",
					            	"sNext": "下一页",
					            	"sLast": "末页"
					            }
					        }
						});
					// 批量上传
					$("#dyntable_length").prepend('<a href="javascript:void(0);" onclick=base.uploadForm() class="radius3"><span>批量上传</span></a>&nbsp;&nbsp;');
					// 删除所选
					$("#dyntable_length").prepend('<button tableid="resourceListTable" id="rmdir" title="删除所选" class="deletebutton radius3">删除所选</button>&nbsp;&nbsp;');
					// 新建目录
					$("#dyntable_length").prepend('<a class="radius3" id="mkdir" href="javascript:;"><span>新建目录</span></a>&nbsp;&nbsp;');
					// 批量删除
					$('#rmdir').unbind('click').click(function(){
						$('<form id="rmdirForm" method="post" action="[@c.url value='/manage/Resource_rmdir.action'/]"></form>').prependTo(document.body);
						$('tbody input[type=checkbox]:checked' ,'#resourceList').each(function(i){
							var path = $(this).parent('td').attr('tval');
							$('#rmdirForm').append("<input type='hidden' name='paths' value='" + path + "' />");
						})
						if ($('input[type=hidden]', '#rmdirForm').length == 0) {
							jAlert("请选择删除的内容", "提示");
						} else {
							// 删除确认
							jConfirm("是否批量删除该资源文件?", "警告", function(r) {
								if (r) {
									$('#rmdirForm').submit();
								}
							});
						}
						return true;
					})
					
					// 新建目录
					$('#mkdir').unbind('click').click(function(){
						var zTree = $.fn.zTree.getZTreeObj("resourceTree");
	                	nodes = zTree.getSelectedNodes();
	                	if (nodes.length==0) {
	                		jAlert('请指定资源文件夹');
	                		return false;
	                	}
	                	var path = nodes[0].path;
						jPrompt('请输入资源路径', '', '提示', function(r) {
							if( r ) {
								$('<form id="rmdirForm" method="post" action="[@c.url value='/manage/Resource_mkdir.action'/]"></form>').prependTo(document.body);
								$('#rmdirForm').append("<input type='hidden' name='path' value='" + path + "/" + r + "' />").submit();
							}
						});
						return false;
					});
				}
				function _addTreeEventListener() {
					var setting = {
						data: {
							simpleData: {
								enable: true
							}
						},
						view: {
							// 渲染树
							addDiyDom: function (treeId, treeNode) {
								// 根节点以外的父节点
								if (treeNode.tId != treeId + "_1" && treeNode.isParent) {
									$('#' + treeNode.tId).append("<a href='javascript:;' onClick=return base.rmDir('" + treeNode.path + "');>[删除]</a>");
								}
							}
						},
						callback: {
							onClick: function(event, treeId, treeNode, clickFlag){
								var path = treeNode.path;
								var isParent = treeNode.isParent;
								var url;
								if (isParent) {
									url = "[@c.url value='/manage/Resource_list.action'/]";
								} else {
									url = "[@c.url value='/manage/Resource_view.action'/]";
								}
								$.get(url, {ajax:true, path:path, piece:true}, function(result){
									$('#resourceList').html(result);
									_addEventListeners();
									_addDateTableRender();
									// 只针对textarea全屏
									if ($('#resourceList').has('textarea').length) {
										$('#resize').show();
									} else {
										$('#resize').hide();
									}
								})
							}
						}
					};
					var zNodes = ${json};
					$.fn.zTree.init($("#resourceTree"), setting, zNodes);
				}
				return {
	                config: {
	                	url : null,
	                    theme: null
	                },
	                init: function () {
	                	_addEventListeners();
	                	_addDateTableRender();
	                	_addTreeEventListener();
	                },
	               	uploadForm : function() {
	                	//批量上传的表单
						var upHtml = '<form action="[@c.url value="/manage/Resource_upload.action"/]" target="uploadResponse" method="post" enctype="multipart/form-data">' +
									'<input type="file" multiple="multiple" class="deletebutton radius3" onchange="base.upladFile(this.form)" name="upload[]">' +
									'<input type="hidden" value="" name="dir" style="margin-left: -117px;"></form>';
						$('#demo').dialog({
							width: 500,
							modal: false
						});
	                },
	                addFile : function(form) {
	                	$('tbody', $(form)).append('<tr><td style="width:65px">文件：</td><td colspan=3><input type="file" class="mediuminput" name="upload"/></td></tr>');
	                },
	                rmDir : function(path) {
	                	$('<form id="rmdirForm" method="post" action="[@c.url value='/manage/Resource_rd.action'/]"></form>').prependTo(document.body);
	                	// 删除确认
						jConfirm("是否批量删除该资源文件夹?", "警告", function(r) {
							if (r) {
								$('#rmdirForm').append("<input type='hidden' name='path' value='" + path + "' />");
								$('#rmdirForm').submit();
							}
						});
	                },
	                upladFile : function(form) {
	                	var zTree = $.fn.zTree.getZTreeObj("resourceTree");
	                	nodes = zTree.getSelectedNodes();
	                	if (nodes.length==0) {
	                		alert('请指定资源文件夹');
	                	}
	                	var path = nodes[0].path;
	                	form.elements[0].value = path;
						//$('<iframe id="uploadResponse" name="uploadResponse" src="javascript:;"></iframe>').prependTo(document.body);
						//$('#loading').html(this.label("Uploading file..."));
						//$('#loading').css('display', 'inline');
						form.submit();
						return false;
	                }
				}
			}());
			
			$(function(){
				var link = "[@c.url value='/manage/Resource_list.action' /]";
				base.config.theme = getTheme();
				base.config.url = link;
	            //Initializing the form
				base.init();
			})
		</script>
	</head>
	<body id="body">
	    <div class="notification msginfo">
	        <a class="close"></a>
	        <p>站点资源文件夹.保存部署站点的所有资源文件</p>
	    </div>
		<!--设置提交行为-->
		<div class="one_fourth">
	    	<div class="widgetbox">
	            <div class="title"><h2 class="general"><span>Resource Tree</span></h2></div>
	            <div class="widgetcontent">
	    			<ul id="resourceTree" class="ztree" style="min-height:280px;"></ul>
	        	</div><!--widgetbox-->
	        </div>
	        <div>
	        	<a href="javascript:alert('正在开发中...')" class="ajax">资源导入</a>
	        	<a href="javascript:alert('正在开发中...')" class="ajax">资源导出</a>
	        </div>
	    </div>
		<div class="three_fourth last" id="fullscreen">
	    	<div class="widgetbox uncollapsible">
	            <div class="title">
	            	<h2 class="general">
	            		<span>Resource List</span>
	            		<a class="tools" href="javascript:void(0);" id="resize" title="全屏" style="display:none;"><i class="icon-fullscreen"></i></a>
	            	</h2>
	            </div>
	            <div class="widgetcontent" style="padding:0px;padding-top:12px;">
	                <div id="resourceList" class="stdtablecb" style="min-height:310px;">
	                </div>
	            </div><!--widgetcontent-->
	        </div><!--widgetbox-->
	    </div>
	    <div id="delete-confirm" style="display:none" title="删除资源文件">
			<p>资源文件删除后将无法恢复.您确认删除吗？</p>
		</div>
	    <div style="clear:both;"></div>
	    
	    <div id="demo" style="display:none;">
	    	<table>
				<tr>
					<td>
						<form action="[@c.url value="/manage/Resource_upload.action"/]" method="post" enctype="multipart/form-data">
							<input type="hidden" name="path" />
							<table style="width:100%" cellspacing="0" cellpadding="0" border="0" class="stdtable-form" id="formItemTable">
								<thead>
									<tr>
										<th class="head0"></th>
										<th class="head1"></th>
										<th class="head0"></th>
										<th class="head1"></th>
									</tr>
								</thead>
								<tbody>
									<tr>
										<td style="width:65px">文件：</td>
										<td colspan=3><input type="file" class="mediuminput" name="upload"/></td>
									</tr>
									<tr>
										<td style="width:65px">文件：</td>
										<td colspan=3><input type="file" class="mediuminput" name="upload"/></td>
									</tr>
									<tr>
										<td style="width:65px">文件：</td>
										<td colspan=3><input type="file" class="mediuminput" name="upload"/></td>
									</tr>
								</tbody>
								<tfoot>
									<th>
										<input type="button" value="增加" onclick="base.addFile(this.form)"/>
									</th>
									<th colspan=3>
										<button class="stdbtn" style="opacity: 1;" onclick="return base.upladFile(this.form)">提&nbsp;&nbsp;&nbsp;&nbsp; 交</button>
									</th>
								</tfoot>
							</table>
						</form>
					</td>
				</tr>
			</table>
	    </div>
	</body>
	</html>
[/#if]